import java.awt.*;
import java.awt.event.*;
import java.awt.image.BufferedImage;
import java.io.*;
import java.lang.reflect.Method;
import java.net.*;
import java.text.NumberFormat;
import java.util.*;
import java.util.logging.Level;

import javax.imageio.ImageIO;
import javax.swing.*;
import javax.swing.event.*;

import org.rsbot.event.listeners.PaintListener;
import org.rsbot.script.Script;
import org.rsbot.script.ScriptManifest;
import org.rsbot.script.methods.*;
import org.rsbot.script.util.Filter;
import org.rsbot.script.wrappers.*;
import org.rsbot.util.GlobalConfiguration;

import org.rsbot.script.wrappers.RSNPC;

@ScriptManifest(authors = "Doout", name = "Roaches V2.0", version = 1.97, description = "")
public class Roaches extends Script implements PaintListener,
		MouseMotionListener, MouseListener {

	public void mouseClicked(MouseEvent e) {

	}

	public void mousePressed(MouseEvent e) {
		Pressed = true;
	}

	public void mouseReleased(MouseEvent e) {
		Pressed = false;
	}

	public void mouseEntered(MouseEvent e) {
	}

	public void mouseExited(MouseEvent e) {
	}

	public void mouseDragged(MouseEvent e) {
		pa.var.paint_m = e.getPoint();
	}

	public void mouseMoved(MouseEvent e) {
		pa.var.m11 = e.getPoint();
	}

	private boolean Pressed;

	public int[] lootIDS;

	private String[] lootnames;

	public int arrow = 886;
	boolean noAmmo = false;

	public int foodIDS = 361;
	public String food1 = "";
	public int food2 = 0;
	private int foodamout = 20;
	ArrayList<ItemsGotten> itemsYouGot = new ArrayList<ItemsGotten>();
	InventoryItemCheck inventoryItemCheck = new InventoryItemCheck();
	public ArrayList<Point> mouseLocs = new ArrayList<Point>();
	SmallMethods SM = new SmallMethods();
	paint pa = new paint();
	int gh = 0;
	int paint;
	int foodprice = 0;
	int food = 0;
	boolean run;

	public boolean safe = false;
	public boolean goman = false;
	public boolean stopfight = true;
	public boolean PT = false;
	public boolean startt = false;
	public boolean guiWait = true;
	public boolean attfreenpc = true;
	public boolean dout = true;
	public boolean gomann = false;
	public boolean NEW = true;
	public boolean fullTurn = true;
	private String Sta = null;
	public int[] itemValues;
	private RSArea inplace = new RSArea(new RSTile(3146, 4274), new RSTile(
			3160, 4281));
	private RSNPC npc;
	private String name;
	// paint
	public String st = "";
	int[] prices;
	int[] charmIDS = { 12158, 12159, 12160, 12161, 12162, 12163, 12164, 12165,
			12166, 12167 };
	public int trainStat, charmcount = 0;
	int currentCharms = 0;
	int showahide = 1;
	public long EXPPerHour;
	public long charmPerHour;
	private final Color backgroundTop = new Color(255, 255, 255, 60),
			title = new Color(255, 125, 0, 200),
			black = new Color(0, 0, 0, 160), white = new Color(255, 255, 255,
					50), red = new Color(255, 30, 30, 200);

	public int bigCrevice = 29728;
	public int rope = 29729;
	int RealHP = 0;

	private RSTile[] toRoaches = { new RSTile(3093, 3491),
			new RSTile(3091, 3491), new RSTile(3089, 3491),
			new RSTile(3087, 3490), new RSTile(3086, 3488),
			new RSTile(3086, 3486), new RSTile(3081, 3484),
			new RSTile(3080, 3483), new RSTile(3080, 3481),
			new RSTile(3080, 3478), new RSTile(3080, 3473),
			new RSTile(3082, 3467), new RSTile(3086, 3465),
			new RSTile(3086, 3462), new RSTile(3081, 3462),
			new RSTile(3079, 3463) };
	NumberFormat nf;
	private RSTile tile = new RSTile(3170, 4269);
	private RSTile tile2 = new RSTile(3093, 3491);
	private RSTile offrope = new RSTile(3153, 4281);
	private RSTile sidecave = new RSTile(3078, 3463);
	private RSTile startfight = new RSTile(3160, 4281);
	private RSTile walktorope = new RSTile(3158, 4278);
	private RSTile[] toBank;
	private int mSpeed;
	private GUIa gui;
	int arrowid;
	private RSGroundItem tileto;
	private final Color color1 = new Color(0, 0, 0, 155), color3 = new Color(0,
			0, 0), color2 = new Color(255, 255, 255);

	private final RenderingHints antialiasing = new RenderingHints(
			RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);

	private final Font font1 = new Font("Arial", 0, 17);

	public void onRepaint(Graphics g1) {
		Graphics2D g = (Graphics2D) g1;
		if (game.isLoggedIn())
			pa.scriptpaint(g);
	}

	public boolean onStart() {
		try {
			gui = new GUIa();
			gui.setVisible(true);
			while (guiWait) {
				sleep(100);
			}
			mouse.setSpeed(mSpeed);
			nf = NumberFormat.getInstance();
			toBank = walking.reversePath(toRoaches);
			RealHP = skills.getRealLevel(3) * 10;
			pa.getLatestVersion();
		} catch (Exception a) {
			SM.printError(a, 3);
		}
		return true;
	}

	@Override
	public int loop() {
		if (npc != null)
			name = npc.getName();
		if (game.isLoggedIn()) {
			Screenshot(1);
			if (inventory.isFull()) {
				inventory.getItem(foodIDS).doAction("Eat");
			}
			inCombatarea();
			if (combat.getLifePoints() < 200) {
				SM.tobankfromnpc();
				obank();
				bank.close();
				eat();
			} else {
				eat();
				if (PT) {
					fight();
				} else {
					SM.loto();
					if (inventory.contains(arrowid)
							&& inventory.getItem(arrowid).getStackSize() >= 50)
						inventory.getItem(arrowid).doAction("Wield");
					if (!stopfight & inventory.contains(foodIDS)) {
						if (getMyPlayer().getInteracting() == null) {
							mainpickup();
						}
						pa.getCount(currentCharms, charmIDS, gh, true);
						if (getMyPlayer().getInteracting() == null
								&& !SM.itempickup()) {
							fight();
							Sta = "Fighting " + name;
							sleep(random(0, 50), random(200, 300));
						}
						if (SM.newNPC() != null) {
							Sta = "Fighting " + name;
							if (getMyPlayer().getInteracting() == null) {
								SM.newNPC().doAction("Attack");
								Sta = "Fighting " + name;
							}
							if (waitToMove(750)) {
								while (getMyPlayer().isMoving()) {
									sleep(random(20, 30));
								}
							}
						}
						if (random(0, 5) == 2 && random(0, 100) == 50)
							antiban();
					}
				}
			}
		}
		return random(20, 40);
	}

	private int inCombatarea() {
		RSTile me = getMyPlayer().getLocation();
		if (!inplace.contains(me) && calc.distanceTo(startfight) < 50)
			walking.walkTo(startfight);
		return 1;
	}

	public boolean waitToMove(int timeout) {
		long start = System.currentTimeMillis();
		RSPlayer myPlayer = getMyPlayer();
		while (System.currentTimeMillis() - start < timeout) {
			if (myPlayer.isMoving())
				return true;
			sleep(15);
		}
		return false;
	}

	private int mainpickup() {
		try {
			for (int i = 0; i < lootIDS.length; i++) {
				while ((tileto = groundItems.getNearest(lootIDS[i])) != null) {
					if (inplace.contains(tileto.getLocation())) {
						if (!calc.tileOnScreen(tileto.getLocation()))
							camera.setAngle(camera.getTileAngle(tileto
									.getLocation()));
						if (calc.distanceTo(tileto.getLocation()) >= 5
								&& calc.distanceTo(tileto.getLocation()) <= 15)
							SM.Walks(tileto.getLocation());
						tileto.doAction("Take " + tileto.getItem().getName());
						Sta = "Picking Up " + lootnames[i];
						sleep(random(100, 300), random(600, 1000));
						inventoryItemCheck.update();
					} else {
						return random(1, 10);
					}
					SM.waitToStop();
				}
			}
		} catch (Exception a) {
			SM.printError(a, 10);
		}
		return random(100, 200);

	}

	public int fight() {
		if (getMyPlayer().getInteracting() == null) {
			if (getMyPlayer().isInCombat()) {
				npc = SM.newNPC();
			} else {
				if (!attfreenpc) {
					npc = npcs.getNearest(new Filter<RSNPC>() {
						public boolean accept(RSNPC n) {
							return n.getInteracting() == null
									&& n.getID() == 7160;
						}
					});
				} else {
					npc = npcs.getNearest(7160);
				}

			}
		}
		if (npc != null) {
			if (calc.tileOnScreen(npc.getLocation())) {
				if (inplace.contains(npc.getLocation())) {
					if (npc.doAction("Attack")) {
						sleep(100, 600);
					}
				} else {
					return random(1, 10);
				}
				return random(100, 120);
			} else {
				if (inplace.contains(npc.getLocation())) {
					camera.setAngle(camera.getTileAngle(npc.getLocation()));
					SM.Walks(npc.getLocation());
					return random(10, 20);
				}
			}
		} else {
			return random(10, 50);
		}
		return random(20, 39);
	}

	private boolean takepic = false;
	private long STime;

	private void Screenshot(int hour) {
		if (!takepic) {
			STime = System.currentTimeMillis();
			takepic = true;
		}
		if (takepic && (System.currentTimeMillis() - STime) >= (3600000 * hour)) {
			this.env.saveScreenshot(true);
			takepic = false;
		}
	}

	public boolean eat() {
		int getHP = combat.getLifePoints();
		int RealHP = skills.getRealLevel(3) * 10;
		if (inventory.contains(foodIDS)) {
			if (getHP <= random(RealHP / 2.0, RealHP / 2.5)) {
				inventory.getItem(foodIDS).doAction("Eat");
				sleep(500, 1000);
			}
		}
		return false;

	}

	private void obank() {
		if (!bank.getInterface().isValid()) {
			final RSObject booth = objects.getNearest(Bank.BANK_BOOTHS);
			if (booth != null) {
				if (calc.distanceTo(booth) > 3 && !booth.isOnScreen()) {
					SM.Walks(booth.getLocation());
					sleep(random(400, 700));
					SM.waitToStop();
					obank();
				}
				booth.doAction("Use-quickly");
				sleep(random(600, 900));
			}

		}
		if (bank.getInterface().isValid()) {
			if (inventory.containsOneOf(lootIDS)) {
				bank.depositAll();
				sleep(random(500, 600));
			} else if (inventory.getCount(foodIDS) < foodamout) {
				// bank.getItem(foodIDS).doAction("Withdraw-" + foodamout);
				bank.withdraw(foodIDS, foodamout);
				sleep(random(600, 800));
			}
		}
	}

	final boolean withdraw(int itemID, int count) {
		final RSItem item = bank.getItem(itemID);
		if (item == null || !item.isComponentValid())
			return false;
		if (!menu.isOpen()) {
			item.getComponent().doClick(false);
			sleep(200, 400);
		}
		if (menu.contains("Withdraw-" + count)) {
			menu.doAction("Withdraw-" + count);
		} else {
			if (menu.contains("Withdraw-X")) {
				sleep(300, 500);
				keyboard.sendText("" + count, false);
				sleep(300, 400);
				keyboard.sendText("", true);
			}
		}
		return false;
	}

	@SuppressWarnings("static-access")
	public void antiban() {
		RSComponent hp = interfaces.getComponent(320, 2);
		switch (random(0, 10)) {
		case 0:
			break;
		case 1:
			keyboard.pressKey((char) KeyEvent.VK_LEFT);
			sleep(random(100, 400));
			keyboard.releaseKey((char) KeyEvent.VK_LEFT);
			break;
		case 2:
			keyboard.pressKey((char) KeyEvent.VK_RIGHT);
			sleep(random(100, 400));
			keyboard.releaseKey((char) KeyEvent.VK_RIGHT);
			break;
		case 3:
			camera.setPitch(true);
			break;
		case 4:
			mouse.moveRandomly(900);
			break;
		case 5:
			if (game.getCurrentTab() != game.TAB_STATS) {
				game.openTab(game.TAB_STATS);
			}
			int sah = random(1, 2);
			if (sah == 2)
				mouse.move(new Point(hp.getAbsoluteX()
						+ random(2, hp.getWidth() - 1), hp.getAbsoluteY()
						+ random(2, hp.getHeight() - 1)));
			sleep(random(900, 2000));
			break;
		case 6:
			int r2 = random(0, 16);
			if (game.getCurrentTab() != r2)
				game.openTab(r2);
			break;
		case 7:
			Point M = new Point(random(0, 300), random(0, 600));
			mouse.move(M);
			switch (random(0, 1)) {
			case 0:
				mouse
						.drag(new Point(M.x + random(0, 200), M.y
								- random(0, 200)));
				break;
			case 1:
				mouse
						.drag(new Point(M.x - random(0, 200), M.y
								+ random(0, 200)));
				break;
			}
			break;
		case 8:
			break;
		case 9:
			break;
		case 10:
			break;
		}
	}

	public void openURL(final String url) {
		final String osName = System.getProperty("os.name");
		try {
			if (osName.startsWith("Mac OS")) {
				final Class<?> fileMgr = Class
						.forName("com.apple.eio.FileManager");
				final Method openURL = fileMgr.getDeclaredMethod("openURL",
						new Class[] { String.class });
				openURL.invoke(null, new Object[] { url });
			} else if (osName.startsWith("Windows")) {
				Runtime.getRuntime().exec(
						"rundll32 url.dll,FileProtocolHandler " + url);
			} else {
				final String[] browsers = { "firefox", "opera", "konqueror",
						"epiphany", "mozilla", "netscape" };
				String browser = null;
				for (int count = 0; count < browsers.length && browser == null; count++) {
					if (Runtime.getRuntime().exec(
							new String[] { "which", browsers[count] })
							.waitFor() == 0) {
						browser = browsers[count];
					}
				}
				if (browser == null) {
					throw new Exception("Could not find web browser");
				} else {
					Runtime.getRuntime().exec(new String[] { browser, url });
				}
			}
		} catch (final Exception e) {

		}
	}

	public int[] extractIntegers(String text) {
		int[] ints = null;
		try {
			text = text.replaceAll(" ", "");
			final String[] strInts = text.split(",");
			ints = new int[strInts.length];
			for (int a = 0; a < strInts.length; a++)
				ints[a] = Integer.parseInt(strInts[a]);
		} catch (final Exception e) {
			log.log(Level.SEVERE, "extractIntegers(String) error: ", e);
		}
		return ints;
	}

	public class GUIa extends JFrame {
		public GUIa() {
			super.setCursor(Cursor.CROSSHAIR_CURSOR);
			initComponents();
		}

		public Properties DooutIni = new Properties();
		public boolean ini = false;
		private DefaultListModel model;
		private DefaultListModel model1;

		private static final long serialVersionUID = -6306987356239712714L;

		private boolean GetIteminfo(String url, DefaultListModel m) {
			try {
				BufferedReader in = new BufferedReader(new InputStreamReader(
						new URL(url).openStream()));
				String str;
				int i = 0;
				String[] Price = GetItemPrice(
						"http://www.firemaw.com/doout/ItemPrice.txt", 70);
				while ((str = in.readLine()) != null) {
					String[] tokens = str.split(",");
					m
							.addElement(tokens[0] + "," + (tokens[1]) + ","
									+ Price[i]);
					i++;
				}
				in.close();
			} catch (IOException ignored) {
			}
			return true;
		}

		private String[] GetItemPrice(String url, int count) {
			String[] Itemprice = null;
			try {
				Itemprice = new String[count];
				int i = 0;
				BufferedReader in = new BufferedReader(new InputStreamReader(
						new URL(url).openStream()));
				String str;
				while ((str = in.readLine()) != null) {
					String[] tokens = str.split(",");
					Itemprice[i] = tokens[0];
					System.out.print(Itemprice[i] + " : ");
					i++;
				}
				in.close();
				return Itemprice;
			} catch (IOException ignored) {
			}
			return null;
		}

		private void list1ValueChanged(ListSelectionEvent e) {
			String text = (String) list1.getSelectedValue();
			if ((text == null) || text.isEmpty()) {
				return;
			}
			model1.addElement(text);
			model.remove(list1.getSelectedIndex());
		}

		private void list2ValueChanged(ListSelectionEvent e) {
			String text = (String) list2.getSelectedValue();
			if ((text == null) || text.isEmpty()) {
				return;
			}
			model.addElement(text);
			model1.remove(list2.getSelectedIndex());
		}

		public boolean loadSettings() {
			try {
				DooutIni.load(new FileInputStream(new File(
						GlobalConfiguration.Paths.getSettingsDirectory(),
						"Doout.ini")));
			} catch (FileNotFoundException e) {
				ini = true;
				return false;
			} catch (IOException e) {
				e.printStackTrace();
				return false;
			}
			if (DooutIni.getProperty("Food") != null)
				comboBox1.setSelectedIndex(Integer.valueOf(DooutIni
						.getProperty("Food")));

			if (DooutIni.getProperty("CustomFood") != null)
				textField1.setText(DooutIni.getProperty("CustomFood"));
			if (DooutIni.getProperty("Foodamout") != null)
				textField2.setText(DooutIni.getProperty("Foodamout"));
			if (DooutIni.getProperty("mouseSpeed") != null)
				slider1.setValue(Integer.valueOf(DooutIni
						.getProperty("mouseSpeed")));
			try {
				BufferedReader in = new BufferedReader(new FileReader(
						GlobalConfiguration.Paths.getSettingsDirectory()
								.concat("Doout.ini")));
				String str;

				String[] Price = GetItemPrice(
						"http://www.firemaw.com/doout/ItemPrice.txt", 60);
				while ((str = in.readLine()) != null) {
					if (!model1.contains(str)) {
						if (str.contains("[]")) {
							return false;
						}
						String delims = ",";
						String[] tokens = str.split(delims);
						String s = (tokens[1]);
						String firstLetter = s.substring(0, 1);
						String remainder = s.substring(1);
						String cap = firstLetter.toUpperCase().replace("[", "")
								+ remainder.toLowerCase().replace("]", "");
						model1.addElement(tokens[0] + "," + cap + ","
								+ tokens[2].replace("]", ""));
						if (model1.firstElement().toString().contains("[")) {
							String ifo = model1.firstElement().toString();
							model1.removeElementAt(0);
							model1.add(0, ifo.substring(1));
						}
						model.removeElement(tokens[0] + "," + cap + ","
								+ tokens[2]);

					}

				}
				in.close();
			} catch (IOException ignored) {
			}
			return true;
		}

		private void button1ActionPerformed(ActionEvent e) {
			boolean pass = false;
			lootIDS = new int[model1.size()];
			for (int i = 0; i < model1.getSize(); i++) {
				String delims = "[,]";
				String[] tokens = ((String) model1.get(i)).split(delims);
				int in = Integer.parseInt(tokens[0]);
				lootIDS[i] = in;
				System.out.print(in + ", :");
			}
			lootnames = new String[model1.size()];
			for (int i = 0; i < model1.getSize(); i++) {
				String delims = "[,]";
				String[] tokens = ((String) model1.get(i)).split(delims);
				lootnames[i] = tokens[1];
			}
			food1 = comboBox1.getSelectedItem().toString();
			if (food1.equals("Custom")) {
				pass = true;
			}
			if (pass) {
				food2 = Integer.parseInt(textField1.getText());
			}
			foodamout = Integer.parseInt(textField2.getText());
			attfreenpc = radioButton1.isSelected();
			PT = radioButton2.isSelected();
			mSpeed = slider1.getValue();
			if (food1.equals("Tuna")) {
				foodIDS = 361;
			} else if (food1.equals("Trout")) {
				foodIDS = 333;
			} else if (food1.equals("Monkfish")) {
				foodIDS = 7946;
			} else if (food1.equals("Lobster")) {
				foodIDS = 379;
			} else if (food1.equals("Swordfish")) {
				foodIDS = 371;
			} else if (food1.equals("Custom")) {
				foodIDS = food2;
			}
			startt = true;
			DooutIni.setProperty("Food", String.valueOf(comboBox1
					.getSelectedIndex()));
			DooutIni.setProperty("trainStat", String.valueOf(comboBox3
					.getSelectedIndex()));
			DooutIni.setProperty("CustomFood", textField1.getText());
			DooutIni.setProperty("Foodamout", textField2.getText());
			DooutIni.setProperty("mouseSpeed", String.valueOf(slider1
					.getValue()));
			DooutIni.setProperty("Powertraing", String.valueOf(radioButton2
					.isSelected()));

			try {
				DooutIni.store(new FileWriter(new File(
						GlobalConfiguration.Paths.getSettingsDirectory(),
						"Doout.ini")),
						"The GUI Settings for Doouts/Script.java");
				if (ini)
					System.out.print("Generated settings file!");
				// log("Generated settings file!");

			} catch (IOException a) {
				// SM.printError(a, 48);
				// log("Saving Fail");
			}
			try {
				BufferedWriter in = new BufferedWriter(new FileWriter(
						GlobalConfiguration.Paths.getSettingsDirectory()
								.concat("Doout.ini")));
				String string = model1.toString();
				String fixed = string.replaceAll(",[ ]", "\r\n");
				in.write(fixed);
				in.close();
			} catch (Exception ex) {
				ex.printStackTrace();
			}
			guiWait = false;
			dispose();
			return;
		}

		private void comboBox1ActionPerformed(ActionEvent e) {
			food1 = comboBox1.getSelectedItem().toString();
			if (food1.equals("Custom")) {
				textField1.setEnabled(true);
			} else {
				textField1.setEnabled(false);
			}

		}

		private void initComponents() {
			// JFormDesigner - Component initialization - DO NOT MODIFY
			// //GEN-BEGIN:initComponents
			button1 = new JButton();
			tabbedPane1 = new JTabbedPane();
			panel1 = new JPanel();
			scrollPane1 = new JScrollPane();
			textPane1 = new JTextPane();
			label6 = new JLabel();
			panel2 = new JPanel();
			label1 = new JLabel();
			comboBox1 = new JComboBox();
			textField1 = new JTextField();
			radioButton1 = new JRadioButton();
			textField2 = new JTextField();
			label4 = new JLabel();
			radioButton2 = new JRadioButton();
			comboBox3 = new JComboBox();
			slider1 = new JSlider();
			label8 = new JLabel();
			separator1 = new JSeparator();
			panel3 = new JPanel();
			scrollPane2 = new JScrollPane();
			list1 = new JList();
			scrollPane3 = new JScrollPane();
			list2 = new JList();
			textField3 = new JTextField();
			label5 = new JLabel();

			// ======== this ========
			setTitle("CockRoach Killer By Firemaw");
			Container contentPane = getContentPane();
			contentPane.setLayout(null);

			// ---- button1 ----
			button1.setText("Start");
			button1.setFont(new Font("Tahoma", Font.PLAIN, 20));
			button1.addActionListener(new ActionListener() {
				public void actionPerformed(ActionEvent e) {
					button1ActionPerformed(e);
				}
			});
			contentPane.add(button1);
			button1.setBounds(5, 525, 585, 25);

			// ======== tabbedPane1 ========
			{
				tabbedPane1.setTabPlacement(SwingConstants.LEFT);
				tabbedPane1.setFont(tabbedPane1.getFont().deriveFont(
						tabbedPane1.getFont().getSize() + 1f));

				// ======== panel1 ========
				{
					panel1.setLayout(null);

					// ======== scrollPane1 ========
					{

						// ---- textPane1 ----
						textPane1
								.setText("This bot was Developed by: Firemaw and Doout. "
										+ "Please keep the forum topic bumped and active "
										+ "by going to http://www.rsbot.org/vb/showthread.php?t=311805");
						textPane1.setEditable(false);
						scrollPane1.setViewportView(textPane1);
					}
					panel1.add(scrollPane1);
					scrollPane1.setBounds(0, 5, 310, 50);

					// ---- label6 ----
					label6
							.setText("<html><img src=http://images1.wikia.nocookie.net/__cb20100601111741/runescape/images/3/3a/Cockroachsoldierpiling.png /></html>");
					panel1.add(label6);
					label6.setBounds(155, 0, 330, 285);

					{ // compute preferred size
						Dimension preferredSize = new Dimension();
						for (int i = 0; i < panel1.getComponentCount(); i++) {
							Rectangle bounds = panel1.getComponent(i)
									.getBounds();
							preferredSize.width = Math.max(bounds.x
									+ bounds.width, preferredSize.width);
							preferredSize.height = Math.max(bounds.y
									+ bounds.height, preferredSize.height);
						}
						Insets insets = panel1.getInsets();
						preferredSize.width += insets.right;
						preferredSize.height += insets.bottom;
						panel1.setMinimumSize(preferredSize);
						panel1.setPreferredSize(preferredSize);
					}
				}
				tabbedPane1.addTab("  Main  ", panel1);
				// ======== panel2 ========
				{
					panel2.setLayout(null);
					// ---- label1 ----
					label1.setText("What Type of food do you want to use?");
					panel2.add(label1);
					label1.setBounds(15, 10, 195, 44);
					// ---- comboBox1 ----
					comboBox1.setModel(new DefaultComboBoxModel(new String[] {
							"Monkfish", "Tuna ", "Lobster", "Trout",
							"Swordfish", "Custom" }));
					comboBox1.addActionListener(new ActionListener() {
						public void actionPerformed(ActionEvent e) {
							comboBox1ActionPerformed(e);
						}
					});
					panel2.add(comboBox1);
					comboBox1.setBounds(new Rectangle(new Point(225, 25),
							comboBox1.getPreferredSize()));

					// ---- textField1 ----
					textField1.setEnabled(false);
					textField1.setText("ID");
					panel2.add(textField1);
					textField1.setBounds(225, 55, 75, 20);

					// ---- radioButton1 ----
					radioButton1
							.setText("Attack a Cockroach's thats being attacked by other player?");
					panel2.add(radioButton1);
					radioButton1.setBounds(10, 205, 350, radioButton1
							.getPreferredSize().height);

					// ---- textField2 ----
					textField2.setText("20");
					panel2.add(textField2);
					textField2.setBounds(225, 85, 30, 20);

					// ---- label4 ----
					label4.setText(" Amount of Food to Withdrawn?");
					panel2.add(label4);
					label4.setBounds(55, 85, 170, 20);

					// ---- radioButton2 ----
					radioButton2.setText("Powertrain? (Will not pick up loot)");
					panel2.add(radioButton2);
					radioButton2.setBounds(10, 230, 270, 25);

					// ---- slider1 ----
					slider1.setPaintLabels(true);
					slider1.setPaintTicks(true);
					slider1.setSnapToTicks(true);
					slider1.setValue(5);
					slider1.setMaximum(10);
					slider1.setMinimum(1);
					slider1.setMinorTickSpacing(1);
					slider1.setMajorTickSpacing(1);
					slider1.setOrientation(SwingConstants.VERTICAL);
					panel2.add(slider1);
					slider1.setBounds(435, 50, 50,
							slider1.getPreferredSize().height);

					// ---- label8 ----
					label8.setText("Mouse Speed Low = Fast");
					panel2.add(label8);
					label8.setBounds(315, 130, 125, 20);
					panel2.add(separator1);
					separator1.setBounds(new Rectangle(new Point(365, 245),
							separator1.getPreferredSize()));

					{ // compute preferred size
						Dimension preferredSize = new Dimension();
						for (int i = 0; i < panel2.getComponentCount(); i++) {
							Rectangle bounds = panel2.getComponent(i)
									.getBounds();
							preferredSize.width = Math.max(bounds.x
									+ bounds.width, preferredSize.width);
							preferredSize.height = Math.max(bounds.y
									+ bounds.height, preferredSize.height);
						}
						Insets insets = panel2.getInsets();
						preferredSize.width += insets.right;
						preferredSize.height += insets.bottom;
						panel2.setMinimumSize(preferredSize);
						panel2.setPreferredSize(preferredSize);
					}
				}
				tabbedPane1.addTab("    Settings    ", panel2);

				// ======== panel3 ========
				{
					panel3.setLayout(null);
					model = new DefaultListModel();
					list1 = new JList(model);
					// ======== scrollPane2 ========
					{
						GetIteminfo(
								"http://www.firemaw.com/doout/ItemInfo.txt",
								model);
						list1
								.addListSelectionListener(new ListSelectionListener() {
									public void valueChanged(
											ListSelectionEvent e) {
										list1ValueChanged(e);
									}
								});
						scrollPane2.setViewportView(list1);
					}
					panel3.add(scrollPane2);
					scrollPane2.setBounds(15, 50, 200, 205);

					// ======== scrollPane3 ========
					{
						model1 = new DefaultListModel();
						list2 = new JList(model1);
						// ---- list2 ----
						list2
								.addListSelectionListener(new ListSelectionListener() {
									public void valueChanged(
											ListSelectionEvent e) {
										list2ValueChanged(e);
									}
								});
						scrollPane3.setViewportView(list2);
					}
					panel3.add(scrollPane3);
					scrollPane3.setBounds(285, 50, 200, 205);

					// ---- textField3 ----
					textField3
							.setText("AutoSave will save all your loot Item.");
					textField3.setEditable(false);
					panel3.add(textField3);
					textField3.setBounds(140, 265, 185, 30);

					{ // compute preferred size
						Dimension preferredSize = new Dimension();
						for (int i = 0; i < panel3.getComponentCount(); i++) {
							Rectangle bounds = panel3.getComponent(i)
									.getBounds();
							preferredSize.width = Math.max(bounds.x
									+ bounds.width, preferredSize.width);
							preferredSize.height = Math.max(bounds.y
									+ bounds.height, preferredSize.height);
						}
						Insets insets = panel3.getInsets();
						preferredSize.width += insets.right;
						preferredSize.height += insets.bottom;
						panel3.setMinimumSize(preferredSize);
						panel3.setPreferredSize(preferredSize);
					}
				}
				tabbedPane1.addTab("Loot", panel3);

			}
			contentPane.add(tabbedPane1);
			tabbedPane1.setBounds(0, 200, 595, 320);

			// ---- label5 ----
			label5
					.setText("<html><img src=http://i651.photobucket.com/albums/uu231/Counterwarrior/BannerforRoaches.jpg /></html>");
			contentPane.add(label5);
			label5.setBounds(0, 0, 595, 195);

			{ // compute preferred size
				Dimension preferredSize = new Dimension();
				for (int i = 0; i < contentPane.getComponentCount(); i++) {
					Rectangle bounds = contentPane.getComponent(i).getBounds();
					preferredSize.width = Math.max(bounds.x + bounds.width,
							preferredSize.width);
					preferredSize.height = Math.max(bounds.y + bounds.height,
							preferredSize.height);
				}
				Insets insets = contentPane.getInsets();
				preferredSize.width += insets.right;
				preferredSize.height += insets.bottom;
				contentPane.setMinimumSize(preferredSize);
				contentPane.setPreferredSize(preferredSize);
			}
			pack();
			loadSettings();
			setLocationRelativeTo(getOwner());
			// JFormDesigner - End of component initialization
			// //GEN-END:initComponents
		}

		// JFormDesigner - Variables declaration - DO NOT MODIFY
		// //GEN-BEGIN:variables
		private JButton button1;
		private JTabbedPane tabbedPane1;
		private JPanel panel1;
		private JScrollPane scrollPane1;
		private JTextPane textPane1;
		private JLabel label6;
		private JPanel panel2;
		private JLabel label1;
		private JComboBox comboBox1;
		private JTextField textField1;
		private JRadioButton radioButton1;
		private JTextField textField2;
		private JLabel label4;
		private JRadioButton radioButton2;
		private JComboBox comboBox3;
		private JSlider slider1;
		private JLabel label8;
		private JSeparator separator1;
		private JPanel panel3;
		private JScrollPane scrollPane2;
		private JList list1;
		private JScrollPane scrollPane3;
		private JList list2;
		private JTextField textField3;
		private JLabel label5;
		// JFormDesigner - End of variables declaration //GEN-END:variables

	}

	public class SmallMethods {
		final void Walks(RSTile[] pathWalk) {
			RSTile[] path = walking.randomizePath(pathWalk, random(1, 2),
					random(1, 2));
			if (calc.distanceTo(walking.getDestination()) < random(4, 6))
				return;
			if (!getMyPlayer().isMoving())
				walking.walkPathMM(path, 2, 2);
			return;
		}

		final private void Walks(final RSTile tile) {
			if (calc.distanceTo(tile) < random(4, 6))
				return;
			if (!getMyPlayer().isMoving())
				walking.walkTo(tile);
		}

		private RSNPC newNPC() {
			RSNPC interacting = npcs.getNearest(new Filter<RSNPC>() {
				public boolean accept(RSNPC n) {
					return n.getInteracting() != null
							&& n.getInteracting().equals(players.getMyPlayer());
				}
			});
			return interacting != null ? interacting : npcs
					.getNearest(new Filter<RSNPC>() {
						public boolean accept(RSNPC npc) {
							return npc.getName().contains("Cockroach Soldier")
									&& npc.getHPPercent() > 0
									&& !npc.isInCombat();
						}
					});
		}

		public void uprope() {
			RSObject ropeup = objects.getNearest(rope);
			if (ropeup != null) {
				if (calc.tileOnScreen(ropeup.getLocation())) {
					camera.setPitch(1024);
					if (ropeup.doAction("Climb")) {
						return;
					} else {
						ropeup.doAction("Climb");
						uprope();
					}
				} else {
					walking.walkTo(walktorope);
				}
			}
		}

		public void walktoCrevice() {
			try {
				RSObject Crevice = objects.getNearest(bigCrevice);
				if (Crevice != null) {
					if (calc.distanceTo(Crevice) <= 5)
						if (calc.tileOnScreen(Crevice.getLocation())) {
							camera.setAngle(camera.getObjectAngle(Crevice));
							objects.getNearest(bigCrevice).doAction("Enter");
							sleep(500, 1000);
						} else {
							Walks(toRoaches);
							sleep(random(2000, 3000));
							Walks(Crevice.getLocation());
						}
				} else {
					Walks(toRoaches);
				}
			} catch (Exception a) {
				printError(a, 57);
			}
		}

		public boolean itempickup() {
			RSGroundItem tiletoloot = groundItems.getNearest(lootIDS);
			if (tiletoloot != null) {
				if (inplace.contains(tiletoloot.getLocation())
						&& getMyPlayer().getInteracting() == null)
					return true;
				return false;
			} else {
				return false;
			}
		}

		public void tonpcfrombank() {
			try {
				Walks(sidecave);
				walktoCrevice();
			} catch (Exception a) {
				printError(a, 7);
			}
			return;
		}

		public void filasafe() {
			try {
				if (inventory.getCount(foodIDS) <= 0 & safe) {
					walking.walkTo(offrope);
					sleep(random(random(500, 550), random(700, 750)));
					safe = false;
				}
			} catch (Exception a) {
				printError(a, 8);
			}
		}

		public void tobankfromnpc() {
			try {
				if (calc.distanceTo(walktorope) < 15) {
					filasafe();
					uprope();
				}
				if (calc.distanceTo(sidecave) <= 10) {
					goman = true;
				}
				if (goman) {
					if (!getMyPlayer().isMoving()) {
						walking.walkPathMM(toBank);
					}
				}
			} catch (Exception a) {
				printError(a, 6);
			}
			return;
		}

		public void loto() {
			int count = inventory.getCount(foodIDS);
			if (calc.distanceTo(tile) <= 7) {
				safe = true;
			}
			if (!new RSArea(new RSTile(3091, 3488), new RSTile(3097, 3499))
					.contains(getMyPlayer().getLocation())
					&& count <= 0) {
				tobankfromnpc();
				Sta = "Walking To Bank";
			}

			if (new RSArea(new RSTile(3091, 3488), new RSTile(3097, 3499))
					.contains(getMyPlayer().getLocation())
					& inventory.getCount(foodIDS) <= 0) {
				obank();
				Sta = "Banking";
			}
			if ((count >= 5) & (calc.distanceTo(tile2) < 100)) {
				tonpcfrombank();
				Sta = "Walking Back ";
			}
			if ((calc.distanceTo(startfight) < 100)) {
				stopfight = false;
			} else {
				stopfight = true;
			}

		}

		private void waitToStop() {
			sleep(random(150, 300));
			if (getMyPlayer().isMoving()) {
				while (getMyPlayer().isMoving()) {
					sleep(random(75, 125));
				}
				sleep(random(111, 333));
			}
		}

		public void printError(Exception e, int number) {
			log("Post this and the error number on the thread:");
			log(e.toString());
			log("Error number:" + number);
			e.printStackTrace();
		}
	}

	/*-------------------------------------------
	 * 	Paint V 1.0
	 * ------------------------------------------
	 */

	private class paint {
		private Var var = new Var();

		private class Var {
			private Point m11 = new Point(0, 0);
			private Point paint_m = new Point(0, 0);
			public long startTime;
			BufferedImage m1 = null;
			BufferedImage m2 = null;
			BufferedImage m3 = null;
			BufferedImage m4 = null;
			BufferedImage m5 = null;

			double startExp[] = null;
			double expToLevel[] = null;
			double expGained[] = null;
			double expPerHour[] = null;
			int counter = 0;
			int offsetY = 345;
			int offsetX = 10;
			final int barWidth = 80;
			final int barHeight = 8;
			public double version = 1.97, latestVersion = 0;
			boolean run = true;
			BufferedImage m = null;
		}

		@SuppressWarnings( { "static-access" })
		public void scriptpaint(Graphics g1) {
			float totalSec = 0;
			long millis = System.currentTimeMillis() - var.startTime;
			final long hours = millis / (1000 * 60 * 60);
			millis -= hours * 1000 * 60 * 60;
			final long minutes = millis / (1000 * 60);
			millis -= minutes * 1000 * 60;
			final long seconds = millis / 1000;
			totalSec = hours * 3600 + minutes * 60 + seconds;
			Graphics2D g = (Graphics2D) g1;
			g.setRenderingHints(antialiasing);
			g.setColor(color1);
			g.drawRoundRect(13, 303, 207, 28, 16, 16);
			g.setColor(color3);
			g.setFont(font1);
			g.drawString("Info", 37, 325);
			g.drawString("Stat", 104, 325);
			g.drawString("Hide", 164, 325);
			int getHP = combat.getLifePoints();
			long moneyMade = inventoryItemCheck.howMuchMoneyIsMade();
			long moneyMadePerHour = 0;

			int mX = var.paint_m.x;
			int mY = var.paint_m.y;
			if (mX >= var.offsetX && mX <= (var.offsetX + 486)
					&& mY >= var.offsetY && mY <= (var.offsetY + 113)) {
				if (Pressed) {
					var.offsetX = mX - (486 / 2);
					var.offsetY = mY - (113 / 2);
				}
			}

			moneyMadePerHour = (int) (3600 * moneyMade / (totalSec));

			for (RSNPC npc : npcs.getAll()) {
				if (npc == null)
					continue;
				advdrawTile(npc.getLocation(), npc, white, g);
			}
			// drawLoot(lootIDS, red, g);
			// int[] npcid = {};
			// for (RSNPC npc : npcs.getAll()) {
			// for (int a : npcid) {
			// if (npc != null)
			// if (npc.getID() == a)
			// advdrawTile(npc.getLocation(), npc, white, g);
			// }
			// }
			if (paint(20, 308, 64, 19)) {
				paint = 1;
			}
			if (paint(85, 309, 64, 18)) {
				paint = 2;
			}
			if (paint(149, 309, 64, 18)) {
				paint = 0;
			}
			mouse(g);
			GetStat();
			if (paint == 0) {
				g.setColor(color2);
				g.drawRoundRect(149, 309, 64, 18, 16, 16);
			}
			if (paint == 1) {
				g.setColor(color1);
				g.fillRoundRect(var.offsetX - 1, var.offsetY, 486, 113, 16, 16);
				g.setColor(color2);
				g.drawRoundRect(20, 308, 64, 19, 16, 16);
				g.setFont(new Font("Meiryo UI", 0, 10));
				g.setColor(backgroundTop);
				g.setColor(new Color(255, 255, 255));
				drawStringWithShadow("Runtime: " + hours + ":" + minutes + ":"
						+ seconds + "   HP : " + getHP + "     " + Sta + "",
						var.offsetX + 10, var.offsetY + 26, g);
				drawStringWithShadow("Version: " + var.version,
						var.offsetX + 10, var.offsetY + 40, g);

				drawStringWithShadow("Total money made: " + moneyMade + " ||  "
						+ moneyMadePerHour + "/Hr", var.offsetX + 200,
						var.offsetY + 40, g);

				if (var.version < var.latestVersion) {
					g.setColor(red);
					drawStringWithShadow("***Outdated***", var.offsetX + 10,
							var.offsetY + 55, g);
					drawStringWithShadow("v" + var.latestVersion
							+ " is available!", var.offsetX + 10,
							var.offsetY + 70, g);
					g.setColor(title);
				} else {
					drawStringWithShadow("Fully updated", var.offsetX + 10,
							var.offsetY + 55, g);
					drawStringWithShadow("Latest version", var.offsetX + 10,
							var.offsetY + 70, g);
				}
			}

			if (paint == 2) {
				g.setColor(color1);
				g.fillRoundRect(var.offsetX - 1, var.offsetY, 486,
						18 * var.counter, 16, 16);

				g.setColor(color2);
				g.drawRoundRect(85, 309, 64, 18, 16, 16);
				g.setColor(Color.white);
				g.setFont(new Font("Calibri", Font.BOLD, 12));
				g.drawString("Skill", var.offsetX + 5, var.offsetY + 15);
				g.drawString("Exp Gained", var.offsetX + 73, var.offsetY + 15);
				g.drawString("Time to level", var.offsetX + 156,
						var.offsetY + 15);
				g.drawString("Exp to level", var.offsetX + 240,
						var.offsetY + 15);
				g.drawString("Exp per hour", var.offsetX + 322,
						var.offsetY + 15);
				g.drawString("%", (var.offsetX + 405 + var.barWidth / 2) - 4,
						var.offsetY + 15);
				var.counter = 1;
				for (int i = 0; i < 24; i++) {
					if ((var.startExp != null)
							&& ((skills.getCurrentExp(i) - var.startExp[i]) > 0)) {
						var.expGained[i] = skills.getCurrentExp(i)
								- var.startExp[i];
						var.expPerHour[i] = skills.getExpToNextLevel(i)
								/ (var.expGained[i] / totalSec);
						var.expPerHour[i] = var.expPerHour[i] / 60;
						var.expToLevel[i] = skills.getExpToNextLevel(i);
						String name = skills.SKILL_NAMES[i];
						final String capitalized = name.substring(0, 1)
								.toUpperCase()
								+ name.substring(1);
						var.counter++;
						g.drawString(capitalized, var.offsetX + 5, var.offsetY
								+ (15 * var.counter));
						if (totalSec >= 0) {
							g
									.drawString(
											pa
													.getFormattedTimeToLevel(var.expPerHour[i]),
											166 + var.offsetX, var.offsetY
													+ (15 * var.counter));
							g
									.drawString(
											""
													+ (int) ((var.expGained[i] * 3600 / totalSec)),
											332 + var.offsetX, var.offsetY
													+ (15 * var.counter));
						}
						g.drawString("" + (int) var.expGained[i],
								83 + var.offsetX, var.offsetY
										+ (15 * var.counter));
						g.drawString("" + (int) var.expToLevel[i],
								250 + var.offsetX, var.offsetY
										+ (15 * var.counter));
						g.setColor(red);
						g.fillRoundRect(var.offsetX + 402, var.offsetY
								+ (15 * var.counter) - var.barHeight,
								var.barWidth, var.barHeight, 10, 10);
						g.setColor(new Color(0, 255, 0));
						g.fillRoundRect(var.offsetX + 402, var.offsetY
								+ (15 * var.counter) - var.barHeight, (skills
								.getPercentToNextLevel(i)
								* var.barWidth / 100), var.barHeight, 10, 10);
						g.setColor(new Color(255, 255, 255, 255));
					}
				}
			}
		}

		@SuppressWarnings("unused")
		private void drawLoot(int[] item, Color color, Graphics g) {
			int Price = 0;
			int Size;
			for (RSGroundItem i : groundItems.getAll()) {
				for (int a : item) {
					if (i.getItem().getID() == a) {
						if (i != null) {
							RSTile w = i.getLocation();
							Point P = calc.tileToScreen(i.getLocation());
							Point SE = calc.tileToScreen(new RSTile(
									w.getX() + 1, w.getY()));
							Point NW = calc.tileToScreen(new RSTile(w.getX(), w
									.getY() + 1));
							Point NE = calc.tileToScreen(new RSTile(
									w.getX() + 1, w.getY() + 1));
							Size = i.getItem().getStackSize();
							if (calc.tileOnScreen(i.getLocation())) {
								g.setColor(color);
								g.setFont(new Font("Meiryo UI", 0, 10));
								g.drawString("Name : " + i.getItem().getName(),
										P.x, P.y);
								g.setColor(Color.BLACK);
								g.drawPolygon(
										new int[] { P.x, SE.x, NE.x, NW.x },
										new int[] { P.y, SE.y, NE.y, NW.y }, 4);
								g.setColor(color);
								g.fillPolygon(
										new int[] { P.x, SE.x, NE.x, NW.x },
										new int[] { P.y, SE.y, NE.y, NW.y }, 4);
							}
						}
					}
				}
			}
		}

		public void getLatestVersion() {
			URLConnection url = null;
			BufferedReader in = null;
			try {
				url = new URL("http://www.firemaw.com/doout/V.txt")
						.openConnection();
				in = new BufferedReader(new InputStreamReader(url
						.getInputStream()));
				var.latestVersion = Double.parseDouble(in.readLine());
			} catch (final Exception e) {
				log("Error loading version data.");
			}
		}

		private void mouse(Graphics g) {
			if (var.m1 != null || var.m2 != null || var.m3 != null
					|| var.m4 != null) {
				final int mx = mouse.getLocation().x;
				final int my = mouse.getLocation().y;
				g.drawImage(var.m, mx, my, null);
				int m_p_x = mouse.getPressLocation().x;
				int m_p_y = mouse.getPressLocation().y;
				long m_p_t = mouse.getPressTime();

				if (System.currentTimeMillis() - m_p_t < 100L) {
					g.setColor(new Color(255, 51, 51, 250));
					g.drawString("C", m_p_x, m_p_y);
				} else if (System.currentTimeMillis() - m_p_t < 200L
						&& System.currentTimeMillis() - m_p_t > 99L) {
					g.setColor(new Color(255, 51, 51, 225));
					g.drawString("Cl", m_p_x, m_p_y);
				} else if (System.currentTimeMillis() - m_p_t < 300L
						&& System.currentTimeMillis() - m_p_t > 199L) {
					g.setColor(new Color(255, 51, 51, 200));
					g.drawString("Cli", m_p_x, m_p_y);
				} else if (System.currentTimeMillis() - m_p_t < 400L
						&& System.currentTimeMillis() - m_p_t > 299L) {
					g.setColor(new Color(255, 51, 51, 175));
					g.drawString("Clic", m_p_x, m_p_y);
				} else if (System.currentTimeMillis() - m_p_t < 500L
						&& System.currentTimeMillis() - m_p_t > 399L) {
					g.setColor(new Color(255, 51, 51, 150));
					g.drawString("Click", m_p_x, m_p_y);
				} else if (System.currentTimeMillis() - m_p_t < 600L
						&& System.currentTimeMillis() - m_p_t > 499L) {
					g.setColor(new Color(255, 51, 51, 125));
					g.drawString("Click", m_p_x, m_p_y);
				} else if (System.currentTimeMillis() - m_p_t < 700L
						&& System.currentTimeMillis() - m_p_t > 599L) {
					g.setColor(new Color(255, 51, 51, 100));
					g.drawString("Clic", m_p_x, m_p_y);
				} else if (System.currentTimeMillis() - m_p_t < 800L
						&& System.currentTimeMillis() - m_p_t > 699L) {
					g.setColor(new Color(255, 51, 51, 75));
					g.drawString("Cli", m_p_x, m_p_y);
				} else if (System.currentTimeMillis() - m_p_t < 900L
						&& System.currentTimeMillis() - m_p_t > 799L) {
					g.setColor(new Color(255, 51, 51, 50));
					g.drawString("Cl", m_p_x, m_p_y);
				} else if (System.currentTimeMillis() - m_p_t < 1000L
						&& System.currentTimeMillis() - m_p_t > 899L) {
					g.setColor(new Color(255, 51, 51, 25));
					g.drawString("C", m_p_x, m_p_y);
				}

				switch (random(1, 5)) {
				case 1:
					var.m = var.m1;
					break;
				case 2:
					var.m = var.m2;
					break;
				case 3:
					var.m = var.m3;
					break;
				case 4:
					var.m = var.m4;
					break;
				case 5:
					var.m = var.m5;
					break;
				}
			}
		}

		public void drawStringWithShadow(final String text, final int x,
				final int y, final Graphics g) {
			final Color col = g.getColor();
			g.setColor(black);
			g.drawString(text, x + 1, y + 1);
			g.setColor(col);
			g.drawString(text, x, y);
		}

		@SuppressWarnings("static-access")
		private void advdrawTile(RSTile tile, RSNPC npc, Color color, Graphics g) {
			int npchight = 500;
			Point minimap = calc.tileToMinimap(tile);
			Point southwestH = calc.tileToScreen(tile, 0, 0, npchight);
			Point southeastH = calc.tileToScreen(new RSTile(tile.getX() + 1,
					tile.getY()), 0, 0, npchight);
			Point northwestH = calc.tileToScreen(new RSTile(tile.getX(), tile
					.getY() + 1), 0, 0, npchight);
			Point northeastH = calc.tileToScreen(new RSTile(tile.getX() + 1,
					tile.getY() + 1), 0, 0, npchight);
			Point southwest = calc.tileToScreen(tile, 0, 0, 0);
			Point southeast = calc.tileToScreen(new RSTile(tile.getX() + 1,
					tile.getY()), 0, 0, 0);
			Point northwest = calc.tileToScreen(new RSTile(tile.getX(), tile
					.getY() + 1), 0, 0, 0);
			Point northeast = calc.tileToScreen(new RSTile(tile.getX() + 1,
					tile.getY() + 1), 0, 0, 0);

			g.setFont(new Font("Meiryo UI", 0, 7));
			g.setColor(color.CYAN);
			// if (minimap != null) {
			// g.setColor(Color.BLACK);
			// g.drawOval(minimap.x, minimap.y, 4, 4);
			// if (npc.getInteracting() == null) {
			// g.setColor(new Color(0, 255, 0));
			// g.drawOval(minimap.x, minimap.y, 4, 4);
			// }
			// if (npc.getInteracting() != null) {
			// g.setColor(red);
			// g.drawOval(minimap.x, minimap.y, 3, 3);
			// g.setColor(Color.WHITE);
			// g.fillOval(minimap.x, minimap.y, 2, 2);
			// }
			// }
			if (calc.pointOnScreen(southwest) && calc.pointOnScreen(southeast)
					&& calc.pointOnScreen(northwest)
					&& calc.pointOnScreen(northeast)) {
				g.setColor(Color.BLACK);
				g.drawPolygon(new int[] { (int) northwest.getX(),
						(int) northwestH.getX(), (int) northeastH.getX(),
						(int) northeast.getX(), (int) southeast.getX(),
						(int) southeastH.getX(), (int) southwestH.getX(),
						(int) southwest.getX() }, new int[] {
						(int) northwest.getY(), (int) northwestH.getY(),
						(int) northeastH.getY(), (int) northeast.getY(),
						(int) southeast.getY(), (int) southeastH.getY(),
						(int) southwestH.getY(), (int) southwest.getY() }, 8);
				g.drawPolygon(new int[] { (int) northwestH.getX(),
						(int) southwestH.getX(), (int) southeastH.getX(),
						(int) northeastH.getX(), (int) northwestH.getX(),
						(int) northwest.getX(), (int) northeast.getX(),
						(int) southeast.getX(), (int) southwest.getX(),
						(int) southwestH.getX() }, new int[] {
						(int) northwestH.getY(), (int) southwestH.getY(),
						(int) southeastH.getY(), (int) northeastH.getY(),
						(int) northwestH.getY(), (int) northwest.getY(),
						(int) northeast.getY(), (int) southeast.getY(),
						(int) southwest.getY(), (int) southwestH.getY() }, 10);
				g.setColor(color);
				g.fillPolygon(new int[] { (int) northwest.getX(),
						(int) northeast.getX(), (int) southeast.getX(),
						(int) southwest.getX() }, new int[] {
						(int) northwest.getY(), (int) northeast.getY(),
						(int) southeast.getY(), (int) southwest.getY() }, 4);
			}

		}

		private String getFormattedNumber(Double p_number) {
			NumberFormat l_nf = NumberFormat.getInstance();
			String l_rVal;
			l_nf.setMaximumFractionDigits(1);
			l_nf.setMinimumFractionDigits(0);

			l_rVal = new String(l_nf.format(p_number.doubleValue()));

			return l_rVal;
		}

		private String getFormattedTimeToLevel(double mins) {
			String st = "";
			if (mins < 1) {
				st = getFormattedNumber((double) mins * 60) + " sec";
				if ((double) mins * 60 > 1)
					st = st + "s";
			} else if (mins >= 1 && mins < 60) {
				st = getFormattedNumber((double) mins) + " mins";
			} else {
				st = getFormattedNumber((double) mins / 60) + " hour";
				if ((double) mins / 60 > 1)
					st = st + "s";
			}
			return st;
		}

		/**
		 * Made by Doout.
		 * 
		 * @return The count of a item.
		 */
		private void getCount(int current, int[] itemid, int inventoryCached,
				boolean stack) {
			int inventorycount = inventory.getCount(stack, itemid);
			if (inventorycount > inventoryCached) {
				inventoryCached++;
				current++;
				getCount(current, itemid, inventoryCached, stack);
			}
			if (inventorycount == 0)
				inventoryCached = 0;
		}

		private boolean paint(final int x, final int y, final int Width,
				final int Height) {
			final Point m = var.m11;
			return m.x >= x && m.x < x + Width && m.y >= y && m.y < y + Height;
		}

		public void GetStat() {
			if (var.run) {
				try {
					var.m1 = ImageIO
							.read(new URL(
									"http://img683.imageshack.us/img683/3931/48201131.png"));
					var.m2 = ImageIO
							.read(new URL(
									"http://img832.imageshack.us/img832/1935/80909174.png"));
					var.m3 = ImageIO
							.read(new URL(
									"http://img411.imageshack.us/img411/7590/22837468.png"));
					var.m4 = ImageIO
							.read(new URL(
									"http://img46.imageshack.us/img46/5280/63992146.png"));
					var.m5 = ImageIO
							.read(new URL(
									"http://img806.imageshack.us/img806/2755/79926533.png"));
					var.startExp = new double[24];
					var.expToLevel = new double[24];
					var.expGained = new double[24];
					var.expPerHour = new double[24];
					for (int i = 0; i < 24; i++) {
						var.startExp[i] = skills.getCurrentExp(i);
						var.expToLevel[i] = skills.getExpToNextLevel(i);
					}
					if (var.latestVersion > var.version) {
						log("This version of  Cockroach Soldiers Pro is now outdated!");
						log("Please visit the RSBot site (www.powerbot.org) for the update!");
					}
					var.startTime = System.currentTimeMillis();
				} catch (Exception a) {
					log("Fail to get Stat");
				}
			}
			var.run = false;
		}
	}

	/*
	 * Credits to DutchSniper
	 */

	public class InventoryItemCheck {
		ArrayList<ItemsGotten> itemsYouGot = new ArrayList<ItemsGotten>();

		public void update() {
			if (game.getCurrentTab() != Game.TAB_INVENTORY) {
				game.openTab(Game.TAB_INVENTORY);
				sleep(500, 700);
			}
			for (RSItem tempItem : inventory.getCachedItems()) {
				boolean hasItem = false;
				for (ItemsGotten anItemYouGot : itemsYouGot) {
					if (anItemYouGot.itemID == tempItem.getID()) {
						hasItem = true;
					}
				}
				if (!hasItem) {
					itemsYouGot.add(new ItemsGotten(tempItem.getID(), true));
				}
			}
			for (ItemsGotten anItemYouGot : itemsYouGot) {
				anItemYouGot.update(true);
			}
		}

		public int howMuchMoneyIsMade() {
			int money = 0;
			for (ItemsGotten tempItem : itemsYouGot) {
				money += tempItem.getTotalPrice();
			}
			return money;
		}
	}

	public class ItemsGotten {
		public int itemID = 0;
		public int itemGotten = 0;
		public int itemQuantityNow = 0;
		public String itemName = null;
		public int thePrice = 0;

		public ItemsGotten(int tempID, boolean count) {
			itemID = tempID;
			itemName = inventory.getItem(itemID).getName();
			itemQuantityNow = inventory.getCount(true, itemID);
			if (count) {
				itemQuantityNow = itemGotten;
			}
			thePrice = grandExchange.getMarketPrice(itemID);
		}

		public int getTotalPrice() {
			return thePrice * itemGotten;
		}

		public void update(boolean count) {
			if (itemQuantityNow < inventory.getCount(true, itemID)) {
				if (count) {
					itemGotten += inventory.getCount(true, itemID)
							- itemQuantityNow;
				}
				itemQuantityNow = inventory.getCount(true, itemID);
			} else if (itemQuantityNow > inventory.getCount(true, itemID)) {
				itemQuantityNow = inventory.getCount(true, itemID);
			}
		}
	}
}
